// pages/look-detail/index.js
const App = getApp();
import Toast from '../../weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    api_root: '',
    nopass_text: '',
    form: {

    },
    deta_form: {
    },
    status: 0,
    type: '',
    id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let api_root = wx.getStorageSync('api_root')
    if (api_root) {
      App.api_root = api_root;
    }
    options.type == 'look' ? this.inspectApplyInfo(options.id) : this.getCustomerDetail(options.id)
    this.setData({
      api_root: App.api_root,
      type: options.type,
      id: options.id,
      status: options.status
    })
    wx.setNavigationBarTitle({
      title: options.type == 'look' ? '带看审核' : '成交审核'
    })
  },
  handleChange(e) {
    console.log(e);
    this.setData({
      nopass_text: e.detail
    })
  },
  handleAgree(e) {
    let { result, text, api, idtype, path } = e.currentTarget.dataset
    let { apply_status } = this.data.deta_form
    let pathR = this.data.type == 'look' ? 'takelook' : 'deallook'
    if (apply_status == 1) {
      result = 'pass_two'
    }
    if (result == 'fail') {
      if (this.data.nopass_text == '') {
        wx.showModal({
          title: '提醒',
          content: '请输入不通过原因',
          showCancel: false
        })
        return false;
      }

    }
    console.log(this.data.id)
    console.log(result)
    console.log(this.data.onpass_text)

    App._post_form(`Customer/${api}`, {
      [idtype]: this.data.id,
      apply_result: result,
      nopass_text: this.data.nopass_text,
    }, function (result) {

      if (result.code === 0) {
        Toast({
          type: 'success',
          message: '提交成功',
          onClose: () => {
            wx.navigateBack({
              delta: 2,
            })
          },
        });
      } else {
        // App.toast('success',result.msg,'pages/userlook-list/deallook')
      }
    })
  },

  //图片预览
  preview(event) {
    console.log(event);
    console.log(event.currentTarget.dataset.src)
    let currentUrl = event.currentTarget.dataset.src
    let imgs = event.currentTarget.dataset.imgs
    imgs = imgs.map(item => {
      return this.data.api_root + item
    })
    console.log(currentUrl)
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: imgs // 需要预览的图片http链接列表
    })
  },

  preview2(event) {
    let currentUrl = event.currentTarget.dataset.src
    let imgs = event.currentTarget.dataset.imgs
    imgs = imgs.map(item => {
      return this.data.api_root + item
    })
    console.log(currentUrl)
    console.log(imgs);
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: imgs // 需要预览的图片http链接列表
    })
  },
  preview3(event) {
    let currentUrl = event.currentTarget.dataset.src
    let imgs = event.currentTarget.dataset.imgs
    imgs = imgs.map(item => {
      return this.data.api_root + item
    })
    console.log(currentUrl)
    console.log(imgs);
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: imgs // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },
  //成交详情
  getCustomerDetail(order_id) {
    let _this = this
    App._post_form('Customer/orderApplyInfo', {
      order_id
    }, function (result) {
      console.log(result)
      _this.setData({
        deta_form: result.data,
      })
      console.log(_this.data.fileList);
    });
  },
  //带看详情
  inspectApplyInfo(record_id) {
    let _this = this
    App._post_form('Customer/inspectApplyInfo', {
      record_id
    }, function (result) {
      console.log(result);
      _this.setData({
        form: result.data
      })
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})